<?xml version="1.0" encoding="UTF-8"?>
<!--
This stylesheet converts taxonomies from their XML representation to
an VDEX tree.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes" encoding="utf-8"/>
	<xsl:param name="contextPath"/>
	
	<xsl:template match="/">
		<vdex xmlns="http://www.imsglobal.org/xsd/imsvdex_v1p0" orderSignificant="true">
			<vocabName>
				<langstring language="en">APKN Subject Vocabulary</langstring>
			</vocabName>
			<vocabIdentifier>org.apkn.metadata.controlledvocabulary</vocabIdentifier>
			<xsl:apply-templates/>
		</vdex>
	</xsl:template>
	<xsl:template match="isComposedBy">
		<xsl:apply-templates select="node"/>
	</xsl:template>
	<xsl:template match="node">
		<term>
				<xsl:variable name="nodePath">
					<xsl:call-template name="getNodePath"/>
				</xsl:variable>
				<xsl:variable name="checkBoxName">cb_<xsl:value-of select="generate-id()"/>
				</xsl:variable>
				<termIdentifier>
					<xsl:value-of select="$nodePath"/>
				</termIdentifier>
				<caption>
					<langstring language="en">
						<xsl:value-of select="@label"/>
					</langstring>
				</caption>

			<!--** render children ** -->
			<xsl:if test="./isComposedBy/node">
					<xsl:apply-templates select="isComposedBy"/>
			</xsl:if>
		</term>
	</xsl:template>
	<xsl:template match="text"/>
	<xsl:template match="text()" priority="-1"/>
	<xsl:template name="getNodePath">
		<xsl:for-each select="ancestor::node"><xsl:value-of select="@label"/>::</xsl:for-each><xsl:value-of select="@label"/>
	</xsl:template>
</xsl:stylesheet>
